

from common import market_to_str
from x_com import source_api
import x_com_lib

from x_com.import_api import realtime_kdata_service_0_0_1


def subscribe_rt_data_to_topic(param: source_api.SubscribeRTDataRequest) -> x_com_lib.PySubscribeTopicInfo:
    subscibe_info = x_com_lib.PySubscribeTopicInfo()
    market_str = market_to_str(param.market)
    subscibe_info.topic = "RtTickData"

    tags = []
    for code in param.code:
        tags.append(f"{market_str}.{code}")

    subscibe_info.tag = tags
    return subscibe_info



    
def copy_min_data(min_data: source_api.MinOrDayData, new_datetime) -> source_api.MinOrDayData:
    new_min_data = source_api.MinOrDayData()
    new_min_data.datetime = new_datetime
    new_min_data.open = min_data.open
    new_min_data.high = min_data.high
    new_min_data.low = min_data.low
    new_min_data.close = min_data.close
    new_min_data.settlement = min_data.settlement
    new_min_data.volume = min_data.volume
    new_min_data.total_turnover = min_data.total_turnover
    new_min_data.open_interest = min_data.open_interest
    new_min_data.average = min_data.average



    return new_min_data